package com.meida.module.bus.provider.controller;

import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.security.OpenHelper;
import com.meida.common.springmvc.base.BaseController;
import com.meida.module.bus.provider.service.BusPayBalanceService;
import com.meida.module.pay.client.entity.PayBalance;
import com.meida.module.pay.provider.service.PayBalanceLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Map;


/**
 * 余额表控制器
 *
 * @author flyme
 * @date 2019-12-16
 */
@Api(tags = "余额信息")
@RestController
@RequestMapping("/bus/balance/")
public class BusPayBalanceController extends BaseController<BusPayBalanceService, PayBalance> {

    @Resource
    PayBalanceLogService payBalanceLogService;

    @ApiOperation(value = "账户余额", notes = "账户余额")
    @GetMapping(value = "getAmount")
    public ResultBody getAmount() {
        return ResultBody.ok(bizService.getByUserIdAndUserType(OpenHelper.getUserId(), "USER"));
    }


    @ApiOperation(value = "余额记录表-分页列表", notes = "余额记录表分页列表 ")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map map) {
        return payBalanceLogService.pageList(map);
    }

    @ApiOperation(value = "申请提现", notes = "申请提现")
    @PostMapping(value = "withdrawals")
    public ResultBody withdrawals(@RequestParam(required = true) BigDecimal money, @RequestParam(required = true) Integer logType) {
        return bizService.withdrawals(OpenHelper.getUserId(), money, logType);
    }

    @ApiOperation(value = "提现记录表-分页列表", notes = "提现记录表分页列表 ")
    @GetMapping(value = "withdrawalsPage")
    public ResultBody withdrawalsPage(@RequestParam(required = false) Map map) {
        return bizService.withdrawalsPage(map);
    }


    @ApiOperation(value = "审批提现", notes = "审批提现")
    @PostMapping(value = "withdrawalsApproval")
    public ResultBody withdrawalsApproval(@RequestParam(required = true) Long balanceLogId, Integer status) {
        return bizService.withdrawalsApproval(balanceLogId, status);
    }

}
